﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace huaguwang.hgmanage.Bogu
{
      public partial class GuPiaoPrice : System.Web.UI.Page
      {
            private readonly D_T_StockExchange_Exp m_dal = new D_T_StockExchange_Exp();
            protected void Page_Load(object sender, EventArgs e)
            {
                  Pager.PageSize = 10;
                  this.WebUserToolBar1.MainInit
                  (
                        UserConst.Exp_GetUser,
                        UserConst.Exp_GetButtonList,
                        (i, but) =>
                        {
                        },
                        UserConst.Exp_ToolBarErr,
                        new huaguwang.WebControls.WebUserToolBar.SelectItem()
                        {
                              FuncGetText = () => TextBox1.Text.Trim(),
                              FuncSetText = v => { TextBox1.Text = v; },
                              Name = TextBox1.ID
                        },
                      new huaguwang.WebControls.WebUserToolBar.SelectItem()
                      {
                            FuncGetText = () => TextBox2.Text.Trim(),
                            FuncSetText = v => { TextBox2.Text = v; },
                            Name = TextBox2.ID
                      },
                      new huaguwang.WebControls.WebUserToolBar.SelectItem()
                      {
                            FuncGetText = () => TextBox3.Text.Trim(),
                            FuncSetText = v => { TextBox3.Text = v; },
                            Name = TextBox3.ID
                      },
                      new huaguwang.WebControls.WebUserToolBar.SelectItem()
                      {
                            FuncGetText = () => TextBox4.Text.Trim(),
                            FuncSetText = v => { TextBox4.Text = v; },
                            Name = TextBox4.ID
                      }
                  );

                  if (!this.IsPostBack)
                  {
                        SetData(0);
                  }
            }

            private void SetData(int begin)
            {
                  var txtTitle = this.WebUserToolBar1.MainGetQuery(this.TextBox1.ID);
                  var txtCode = this.WebUserToolBar1.MainGetQuery(this.TextBox2.ID);
                  DateTime? dtBegin=null;
                  DateTime? dtEnd = null;
                  if (this.WebUserToolBar1.MainGetQuery(this.TextBox3.ID) != "") 
                  {
                        dtBegin = this.WebUserToolBar1.MainGetQuery(this.TextBox3.ID).Exp_DateTimeTryParse();
                  }
                  if (this.WebUserToolBar1.MainGetQuery(this.TextBox4.ID) != "") 
                  {
                        dtEnd = this.WebUserToolBar1.MainGetQuery(this.TextBox4.ID).Exp_DateTimeTryParse();
                  }
                  var count = 0;
                  this.Repeater1.DataSource = m_dal.GetStockExchageList(begin, Pager.PageSize, txtTitle, txtCode, dtBegin, dtEnd, ref count);
                  this.Repeater1.DataBind();
                  Pager.RecordCount = count;
            }


            protected void WebUserToolBar1_Button0(object sender, EventArgs e)
            {
                  AdminPublic.Try(() =>
                  {
                        WebUserToolBar1.MainSetQuery();
                        SetData(0);
                  });
            }

            /// <summary>
            /// 分页控件的页面事件
            /// </summary>
            protected void Pager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
            {
                  SetData((e.NewPageIndex - 1) * Pager.PageSize);
            }
      }
}
